﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TestWebApplication.CommerceTransaction;
using TestWebApplication.CommerceTestDataProvider;
using Microsoft.Commerce.Proxy.TransactionService.v201001;
using TestWebApplication.CommercePaymentInstrument;
using CommercePIProxy = Microsoft.Commerce.Proxy.PaymentInstrumentService;
using CommerceAccountProxy = Microsoft.Commerce.Proxy.AccountService;


namespace TestWebApplication
{
    public partial class purchase1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            itemID.Text = Request["itemID"];

            PurchaseContentViewModel purchaseInfo = (PurchaseContentViewModel)Session["purchaseInfo"];
            title.Text = purchaseInfo.ContentCatalog.contentName;
            amount.Text = purchaseInfo.ContentCatalog.contentAmount.ToString();
           // piid.Text = "mDoAAAAAAAABAACA";
            piid.Text = Request["piid"];
            if (String.IsNullOrEmpty(piid.Text)) piid.Text = "You have not chosen a Payment Instrument";

        }

        protected void buy_Click(object sender, EventArgs e)
        {
            PurchaseContentViewModel purchaseInfo = (PurchaseContentViewModel)Session["purchaseInfo"];
            purchaseInfo.CreditCardPaymentMethodId = piid.Text;
            Session["purchaseInfo"] = purchaseInfo;
            if (MINTPurchaseHandler.PurchaseContent((CommerceAccountProxy.Identity)Session["requester"], purchaseInfo))
                Response.Redirect("PurchaseSuccess.aspx");
            else
                Response.Redirect("PurchaseFailure.aspx");
        }

        protected void addPI_Click(object sender, EventArgs e)
        {
            string itemID = Request["itemID"];
            string locale = (string)Session["locale"];
            string accountID = (string)Session["accountID"];

            string url = PCSHandler.generatePCSUrl(locale, itemID, accountID);

            Response.Redirect(url);
        }
    }
}